<template>
	<view id="page">
		<!-- 顶部搜索栏/菜单栏 -->
		<view class="top-bar">
			<view class="scan-icon" @click="goUnder">
				<image lazy-load="true"  src="../../static/images/icon-position.png" class="ico"></image>
				<view class="text">线下门店</view>
			</view>
			<view class="search-input" @click="goSearchPage">
			<image lazy-load="true"  src="../../static/images/search-ico.png" class="search-ico"></image>
			<input type="text"  placeholder="北欧简约风沙发" :disabled="true"  v-model="inputVal" confirm-type="search"  @confirm="search_good" placeholder-style="color:#cccccc">
			<image lazy-load="true" v-if="inputVal" @click="cleanInput()" src="../../static/images/close-btn.png" class="close-btn"></image>
				
			</view>
			<view class="message-icon" @click="goNew">
				<image lazy-load="true"  src="../../static/images/icon-2.png" class="ico"></image>
				<view class="text">消息</view>
				<view v-if="show_notice>0" class="badge_d" ></view>
			</view>
		</view>
		<view class="key-word-box">
			<scroll-view scroll-x="true">
				<view class="key-word">
					<view @click="goAllGoodsList()" class="tag">所有商品</view>
					<view @click="goCustom" class="tag">定制家具</view>
					<view @click="goVideo" class="tag">家具视频</view>
					<view @click="goCostomiza" class="tag">样板间专区</view>
					<view @click="goCloth" class="tag">布艺世界</view>
					<view @click="goShare" class="tag">分享得佣金</view>
					<view @click="goClassify" class="tag">所有分类</view>
				</view>
			</scroll-view>
		</view>
		<!-- banner -->
		<view class="banner">
			<swiper :indicator-dots="true" indicator-active-color="gray" indicator-color="#cccccc" :autoplay="true"  class="banner-img">
				<!-- <swiper-item>
					<image @click="goVideo" class="banner-img" lazy-load="true" src="../../static/images/video_banner.png" mode="aspectFit"></image>
				</swiper-item> -->
				<swiper-item v-for="(item,key) in home_data.index_banner" :key="key">
					<image  class="banner-img" lazy-load="true" :src="item.image" @click="goType(item)" mode="aspectFit"></image>
				</swiper-item>
				<!-- <swiper-item>
					<image class="banner-img" lazy-load="true" src="https://weizong.file.cxbyi.com/images/banner_1.jpg" mode="aspectFit"></image>
				</swiper-item> -->
			</swiper>
		</view>
		<view class="banner" v-if="home_data.index_banner_1_1">
			<swiper :indicator-dots="true" indicator-active-color="gray" indicator-color="#cccccc" :autoplay="true"  class="banner-img">
				<!-- <swiper-item>
					<image @click="goVideo" class="banner-img" lazy-load="true" src="../../static/images/video_banner.png" mode="aspectFit"></image>
				</swiper-item> -->
				<swiper-item v-for="(item,key) in home_data.index_banner_1_1" :key="key">
					<image  class="banner-img" lazy-load="true" :src="item.image" @click="goType(item)" mode="aspectFit"></image>
				</swiper-item>
				<!-- <swiper-item>
					<image class="banner-img" lazy-load="true" src="https://weizong.file.cxbyi.com/images/banner_1.jpg" mode="aspectFit"></image>
				</swiper-item> -->
			</swiper>
		</view>
		<view v-for="(item,key) in costomiza_list" :key="key" @click="goCostomizaDetail(item.id)" class="costomiza_list">
			<view class="cos-img"><image :src="item.images" class="cos-img" mode="widthFix"></image></view>
			<view class="msg">
				<view class="big-msg">{{item.title}}</view>
				<view class="tag1">家具体验</view>
			</view>
			<view class="mark">{{item.intro}}</view>
		</view>
		<view class="more-goods" @click="goCostomiza">更多样板间>></view>
		
		
		<view class="part part1">
			<view class="part-img-box" v-if="home_data.mini_2_0">
				<image v-for="(item,key) in home_data.mini_2_0" :key="key" :src="item.image"  @click="goType(item)" class="part-img" mode="widthFix"></image>
			</view>
			<view class="part-img-box" v-if="home_data.mini_2_1">
				<image v-for="(item,key) in home_data.mini_2_1" :key="key" :src="item.image"  @click="goType(item)" class="part-img" mode="widthFix"></image>
			</view>
			<view class="part-img-box" v-if="home_data.mini_2_2">
				<image class="part-sm-img" v-for="(item,key) in home_data.mini_2_2" :key="key" :src="item.image"  @click="goType(item)" mode="widthFix"></image>
			</view>
			<view class="part-img-box" v-for="(item,key) in home_data.mini_2_3" :key="key">
				<image :src="item.image"  @click="goType(item)" class="part-img" mode="widthFix"></image>
			</view>
			<view class="part-img-box no-margin" v-for="(item,key) in home_data.mini_2_4" :key="key">
				<image :src="item.image"  @click="goType(item)" class="part-img" mode="widthFix"></image>
			</view>
		</view>
		<view class="part part1">
			<view class="part-img-box" v-if="home_data.bed_3_0">
				<image v-for="(item,key) in home_data.bed_3_0" :key="key" :src="item.image"  @click="goType(item)" class="part-img" mode="widthFix"></image>
			</view>
			<view class="part-list">
				<view class="img-box">
					<image class="list-img" v-for="(item,key) in home_data.bed_3_1" :key="key" v-if="key<2" :src="item.image"  @click="goType(item)" mode="widthFix"></image>
				</view>
				<view class="">
					<image class="big-img" v-for="(item,key) in home_data.bed_3_2" :key="key" :src="item.image"  @click="goType(item)"  mode="widthFix"></image>
				</view>
			</view>
			<view>
				<image class="list-image" v-for="(item,key) in home_data.bed_3_1" :key="key" v-if="key>1" :src="item.image"  @click="goType(item)" mode=""></image>
			</view>
		</view>
		<view class="part part1">
			<view class="part-img-box" v-if="home_data.customized_4_0">
				<image v-for="(item,key) in home_data.customized_4_0" :key="key" :src="item.image"  @click="goType(item)" class="part-img" mode="widthFix"></image>
			</view>
			<view class="">
				<image class="list-image-2" v-for="(item,key) in home_data.customized_4_1" :key="key" :src="item.image"  @click="goType(item)"  mode=""></image>
			</view>
		</view>
		<view class="part part1">
			<view class="part-img-box" v-for="(item,key) in home_data.customized_4_2" :key="key" >
				<image :src="item.image"  @click="goType(item)" class="part-img" mode="widthFix"></image>
			</view>
		</view>
		<view class="part part1">
			<view class="part-img-box" v-if="home_data.c_style_5_0">
				<image v-for="(item,key) in home_data.c_style_5_0" :key="key" :src="item.image"  @click="goType(item)" class="part-img" mode="widthFix"></image>
			</view>
			<view class="part-img-box" v-for="(item,key) in home_data.c_style_5_1" :key="key">
				<image :src="item.image"  @click="goType(item)" class="part-img" mode="widthFix"></image>
			</view>
		</view>
		<view class="part part1">
			<view class="part-img-box">
				<image src="../../static/images/p7.png" class="part-img" mode="widthFix"></image>
			</view>
		</view>
		<yuKeFu tel="13684076389"></yuKeFu>
		<view class="lottery_box" v-if="show_lottery_box">
			<image src="../../static/images/goods-add-delete.png" class="close_lottery" @click="close_lottery_box"></image>
			<image :src="lottery_img" @click="start_lottery" class="lottery_img" mode="widthFix"></image>
		</view>
	</view>
	
</template>
<script>
	export default {
		data() {
			return {
				showUnderline:1,
				color1:"#000000",
				color2:"#999999",
				hideBody1:false,
				tags:[],
				home_data:[],
				fashionList:[],
				guessLike:[],
				mustBuy:[],
				mustGrab:[],
				detailList:[],
				show_notice:0,
				inputVal:'',
				lottery_img:'',
				show_lottery_box:false,
				lottery_data:{},
				is_lottery:false,
				is_click:false,
				lottery_type:'',
				user_obj:{},
				share_id:0,
				costomiza_list:[]
			}
		},
		onLoad() {
			var self = this;
			self.user_obj = uni.getStorageSync('user');
			let user_id = self.user_obj.id;
			let share_id = uni.getStorageSync('share_id') ? uni.getStorageSync('share_id') : 0;
			if(user_id && share_id){
				self.$request.request({
					url:'/user/set_bind',
					data:{
						send_user_id:share_id,
						receive_user_id:user_id
					},
					success:function(res){
						
					}
				});
			}
			console.log(this.$store.getters.getGoodsList);
			var arr=[{'name':'张三'},{'name':'李四'},{'name':'王五'}]
			this.$store.dispatch('setGoodsList',arr)
			self.show_notice = parseInt(uni.getStorageSync('notice'));
			//关键字
			// this.$request.request({
			// 	url:'/search/goods_tags',
			// 	success:function(res){
			// 		if(res.code==200){
			// 			self.tags = res.result;
			// 		}else{
						
			// 		}
			// 	}
			// });
			this.$request.request({
				url:'/home?version=2.0',
				success:function(res){
					if(res.code==200){
						var x = res.result;
						console.log(x)
						if(x.index_banner){
							x.index_banner.forEach((item,index)=>{
								x.index_banner[index].image=self.$http_img(item.image);
								if(item.type=="3"){
									x.index_banner[index].url=self.$http_url(item.url);
								}
							});
						}
						if(x.index_banner_1_1){
							x.index_banner_1_1.forEach((item,index)=>{
								x.index_banner_1_1[index].image=self.$http_img(item.image);
								if(item.type=="3"){
									x.index_banner_1_1[index].url=self.$http_url(item.url);
								}
							});
						}
						if(x.mini_2_0){
							x.mini_2_0.forEach((item,index)=>{
								x.mini_2_0[index].image=self.$http_img(item.image);
							});
						}
						if(x.mini_2_1){
							x.mini_2_1.forEach((item,index)=>{
								x.mini_2_1[index].image=self.$http_img(item.image);
							});
						}
						if(x.mini_2_2){
							x.mini_2_2.forEach((item,index)=>{
								x.mini_2_2[index].image=self.$http_img(item.image);
							});
						}
						if(x.mini_2_3){
							x.mini_2_3.forEach((item,index)=>{
								x.mini_2_3[index].image=self.$http_img(item.image);
							});
						}
						if(x.mini_2_4){
							x.mini_2_4.forEach((item,index)=>{
								x.mini_2_4[index].image=self.$http_img(item.image);
							});
						}
						if(x.bed_3_0){
							x.bed_3_0.forEach((item,index)=>{
								x.bed_3_0[index].image=self.$http_img(item.image);
							});
						}
						if(x.bed_3_1){
							x.bed_3_1.forEach((item,index)=>{
								x.bed_3_1[index].image=self.$http_img(item.image);
							});
						}
						if(x.bed_3_2){
							x.bed_3_2.forEach((item,index)=>{
								x.bed_3_2[index].image=self.$http_img(item.image);
							});
						}
						if(x.customized_4_0){
							x.customized_4_0.forEach((item,index)=>{
								x.customized_4_0[index].image=self.$http_img(item.image);
							});
						}
						if(x.customized_4_1){
							x.customized_4_1.forEach((item,index)=>{
								x.customized_4_1[index].image=self.$http_img(item.image);
								
							});
							console.log(x.customized_4_1)
						}
						if(x.customized_4_2){
							x.customized_4_2.forEach((item,index)=>{
								x.customized_4_2[index].image=self.$http_img(item.image);
							});
						}
						if(x.c_style_5_0){
							x.c_style_5_0.forEach((item,index)=>{
								x.c_style_5_0[index].image=self.$http_img(item.image);
							});
						}
						if(x.c_style_5_1){
							x.c_style_5_1.forEach((item,index)=>{
								x.c_style_5_1[index].image=self.$http_img(item.image);
							});
						}
						self.home_data=x;
						
					}else{
						
						
					}
				}
			});
			this.$request.request({
				url:'/category/recommend',
				data:{
					
				},
				success:function(res){
					if(res.code==200){
						res.result.categories.forEach((item,index)=>{
							res.result.categories[index].logo = self.$http_img(item.logo)
						})
						self.detailList = res.result;
					}else{
						
					}
				}
			});
			this.$request.request({
				url:'/sample/recommend',
				data:{
					
				},
				success:function(res){
					if(res.code==200){
						var x = res.result;
						x.forEach((item,index)=>{
							x[index].images = self.$http_img(item.images)
						})
						self.costomiza_list = x;
						console.log(self.costomiza_list)
					}else{
						
					}
				}
			});
			// #ifdef H5
			
			
			let share_time_line={
				title:'', // 分享标题
				link: self.$request.h5_share_url+'?page=index&share='+(self.user_obj ? self.user_obj.id : 0), // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: self.$request.h5_img_url+'/static/images/logo.png', // 分享图标
			}
			let share_app_message={
				title: '', // 分享标题
				desc: '', // 分享描述
				link: self.$request.h5_share_url+'?page=index&share='+(self.user_obj ? self.user_obj.id : 0), // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: self.$request.h5_img_url+'/static/images/logo.png', // 分享图标
			}
			uni.setStorageSync('share_time_line',share_time_line);
			uni.setStorageSync('share_app_message',share_app_message);
			self.$request.wx_config()
			
			// #endif
			
			
		},
		onShow() {
			var self = this;
			self.is_click = false;
			self.show_lottery_box= false;
			this.$request.request({
				url:'/home/get_register_reward',
				data:{
					
				},
				success:function(res){
					if(res.code==200){
						var data = res.result;
						if(data.ingot||data.redpacket){
							data.config.image = self.$http_img(data.config.image);
							data.config.ingot_image = self.$http_img(data.config.ingot_image);
							data.config.red_packet_image = self.$http_img(data.config.red_packet_image);
							self.lottery_data = data;
							self.lottery_img = data.config.image;
							self.show_lottery_box = true;
						}
					}else{
						
					}
				}
			})
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {
		     
		    }
		    return {
		      title: this.$request.share_title,
		      path: '/pages/index/index&share='+(self.user_obj ? self.user_obj.id : 0)
		    }
		  },
		methods: {
			start_lottery(){
				var self = this;
				if(!self.is_lottery&&!self.is_click){
					self.is_click = true;
					this.$request.request({
						url:'/home/register_reward',
						data:{
							
						},
						success:function(res){
							var data = res.result;
							if(res.code==200){
								self.is_lottery = true;
								if(self.lottery_data.ingot){
									self.lottery_img = self.lottery_data.config.ingot_image;
									self.show_lottery_box = true;
									self.lottery_type = 'ingot'
								}
								if(self.lottery_data.redpacket){
									self.lottery_img = self.lottery_data.config.red_packet_image;
									self.show_lottery_box = true;
									self.lottery_type = 'red_packet'
								}
								self.is_click = false;
							}else if(res.code==40003){
								uni.navigateTo({
									url:'../login/login?page=index'
								})
							}
						}
					})
				}else{
					self.show_lottery_box = false;
					if(self.lottery_type == 'ingot'){
						uni.switchTab({
						    url: '/pages/guaguaka/guaguaka'
						});
					}
				}
				
				
			},
			close_lottery_box(){
				this.show_lottery_box = false;
			},
			cleanInput(){
				this.inputVal ="";
			},
			goDetails(id){
				uni.navigateTo({
				    url: '../local-store-item/local-store-item?id='+id
				});
			},
			goClassify(){
				uni.navigateTo({
				    url: '../classify-more/classify-more'
				});
			},
			goSearchPage(){
				uni.navigateTo({
				    url: '../search/search'
				});
			},
			goNew(){
				this.$request.request({
					url:'/user/info',
					success:function(res){
						if(res.code==200){
							uni.setStorageSync('notice',0);
							uni.navigateTo({
							    url: '../news/news'
							});
						}
						if(res.code==40003){
							uni.navigateTo({
								url:'../login/login?page=index'
							})
						}
					}
				});
				
			},
			goType(obj){
				if(obj.type=="1"){
					this.goDetails(obj.store_sku_id)
				}
				if(obj.type=="2"){
					this.bannerGoGoodsList(obj.category,obj.style)
				}
				if(obj.type=="3"){
					window.location.href=obj.url
				}
			},
			goGoodsList(id){
				uni.navigateTo({
				    url: '../good-list/good-list?id='+id
				});
			},
			bannerGoGoodsList(id,ids){
				uni.navigateTo({
				    url: '../good-list/good-list?catgray_id='+id.join('_')+'&style_id='+ids.join('_')
				});
			},
			goCustom(){
				uni.navigateTo({
				    url: '../../pagesA/custom/custom'
				});
			},
			goCostomiza(){
				uni.navigateTo({
				    url: '../../pagesA/model-room/model-room'
				});
			},
			goCostomizaDetail(id){
				uni.navigateTo({
				    url: '../../pagesA/model-room-detail/model-room-detail?id='+id
				});
			},
			search_good(e){
				uni.navigateTo({
				    url: '../good-list/good-list?search='+encodeURIComponent(e.detail.value)
				});
			},
			goAllGoodsList(){
				uni.navigateTo({
				    url: '../good-list/good-list'
				});
			},
			goUnder(){
				uni.switchTab({
				    url: '/pages/shop/shop'
				});
			},
			goShare(){
				uni.switchTab({
				    url: '/pages/share/share'
				});
			},
			goVideo(){
				uni.navigateTo({
				    url: '../video/video'
				});
			},
			goCloth(){
				uni.navigateTo({
				    url: '../cloth-area/cloth-area'
				});
			},
			textKu(){
				// window.location.href="https://pano.kujiale.com/cloud/design/3FO4BP8WGJJ6/show?from=groupmessage&fromqrcode=true&isappinstalled=0"
			},
			goLottery(){
				uni.switchTab({
				    url: '/pages/guaguaka/guaguaka'
				});
			}
		}
	}
</script>

<style>
	@import url("index.css");
</style>
